
#include "MainUi.h"
#include "assert.h"
#include "SensorMonitor.h"
#include "SpeedMonitor.h"
#include "Snap.h"
#include "SnapCaculator.h"
#include "SnapGenerator.h"
#include "settingDlg.h"
#include "Warnning.h"
#include <qlabel.h>
#include <qtabwidget.h>
#include <qlistview.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qtextcodec.h>
#include <stdio.h>

MainUi::MainUi( QWidget* parent, const char* name, WFlags fl):
	MainDialog(parent, name, fl)
{

	QTextCodec* code = QTextCodec::codecForName("Utf-8");

	QString str = code->toUnicode(tr("停止中"));
    stateButton0->setText(str); 
    stateButton1->setText(str); 
    stateButton2->setText(str); 


	m_pipeLine[0] = new PipeLine(0);
	connect(m_pipeLine[0], SIGNAL(stateChange(const QString&)), this, SLOT(state0Change(const QString&)));

	m_pipeLine[1] = new PipeLine(1);
	connect(m_pipeLine[1], SIGNAL(stateChange(const QString&)), this, SLOT(state1Change(const QString&)));


	m_pipeLine[2] = new PipeLine(2);
	connect(m_pipeLine[2], SIGNAL(stateChange(const QString&)), this, SLOT(state2Change(const QString&)));


	m_sensorMonitor = new SensorMonitor();



	m_pipeLine[0]->registerNotify(m_sensorMonitor);
	m_pipeLine[1]->registerNotify(m_sensorMonitor);
	m_pipeLine[2]->registerNotify(m_sensorMonitor);

	m_sensorMonitor->start(); 


	m_sldlg[0] = new SelectDialog(this, tr("select dialog"), true, WStyle_Customize | WStyle_NoBorder);
	m_sldlg[1] = new SelectDialog(this, tr("select dialog"), true, WStyle_Customize | WStyle_NoBorder);
	m_sldlg[2] = new SelectDialog(this, tr("select dialog"), true, WStyle_Customize | WStyle_NoBorder);

	m_sldlg[0]->setFixedSize(240, 320);
	m_sldlg[1]->setFixedSize(240, 320);
	m_sldlg[2]->setFixedSize(240, 320);
	connect(stateButton0, SIGNAL(clicked()), m_sldlg[0], SLOT(show()));
	connect(stateButton1, SIGNAL(clicked()), m_sldlg[1], SLOT(show()));
	connect(stateButton2, SIGNAL(clicked()), m_sldlg[2], SLOT(show()));

	connect(m_sldlg[0]->settingBtn, SIGNAL(clicked()), m_pipeLine[0], SLOT(settingDlgShow()));
	connect(m_sldlg[1]->settingBtn, SIGNAL(clicked()), m_pipeLine[1], SLOT(settingDlgShow()));
	connect(m_sldlg[2]->settingBtn, SIGNAL(clicked()), m_pipeLine[2], SLOT(settingDlgShow()));

	connect(m_sldlg[0]->historyBtn, SIGNAL(clicked()), m_pipeLine[0], SLOT(historyDlgShow()));
	connect(m_sldlg[1]->historyBtn, SIGNAL(clicked()), m_pipeLine[1], SLOT(historyDlgShow()));
	connect(m_sldlg[2]->historyBtn, SIGNAL(clicked()), m_pipeLine[2], SLOT(historyDlgShow()));

}



MainUi::~MainUi()
{
	delete m_pipeLine[0];
	delete m_pipeLine[1];
	delete m_pipeLine[2];

	delete m_sldlg[0];
	delete m_sldlg[1];
	delete m_sldlg[2];

}
void MainUi::state0Change(const QString& str)
{
	stateButton0->setText(str);
}
void MainUi::state1Change(const QString& str)
{
	stateButton1->setText(str);
}

void MainUi::state2Change(const QString& str)
{
	stateButton2->setText(str);
}
